package com.coda;

import com.coda.mapper.WordMapper;
import com.coda.pojo.Word;
import com.coda.pojo.dto.WordDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.Random;

/**
 * 修改数据库中的数据
 */
@SpringBootTest
public class ChangeData {
    @Autowired
    private WordMapper wordMapper;
    @Test
    public void changePartOfSpeech() {
        String str = "av.testdfjsfk";
        int index = str.indexOf(".");
        if (index != -1) {
            System.out.println(str.substring(0, index));
        }
        //获取单词数量
        List<Word> wordAll = wordMapper.getWordAll(new WordDTO());
        for (int i = 1; i <= wordAll.size(); i++) {
            //根据id获取单词
            Word word = wordMapper.getwordById(i);
            System.out.println(word);
        }
//        wordMapper.changePartOfSpeech();
    }

    //修改单词status
    @Test
    public void changeStatusWord() {
        Random random = new Random();
        List<Word> wordAll = wordMapper.getWordAll(new WordDTO());
        for (int i = 0; i < wordAll.size(); i++) {
            int j = random.nextInt(3)+1;
            Word word = new Word();
            word.setId(wordAll.get(i).getId());
            word.setStatus(String.valueOf(j));
            wordMapper.update(word);
        }

    }
}
